package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.corona.Game;
import com.corona.game.util.TextureCache;

/* compiled from: Battle.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/EggHatchAnim.class */
public class EggHatchAnim extends Action {
    public Action.Layer layer = Action.Layer.gui_130;
    public Sprite bgSprite = new Sprite(TextureCache.get(Gdx.files.internal("battle/intro_frame6.png")), 0, 0, 160, 144);
    Pokemon pokemon;
    public static boolean drawPostHatchBottom = false;
    public static boolean drawPostHatchTop = false;
    public static boolean drawSprite = false;
    public static boolean isDone = false;

    public EggHatchAnim(Pokemon pokemon, Action nextAction) {
        super(new Object[0]);
        this.pokemon = pokemon;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        drawPostHatchBottom = false;
        drawPostHatchTop = false;
        drawSprite = false;
        isDone = false;
        this.pokemon.hatch();
        game.battle.oppPokemon = this.pokemon;
        FileHandle fileHandle = Gdx.files.internal("attacks/egg_hatch_gsc/output/frame-452.png");
        Texture text = TextureCache.get(fileHandle);
        TextureData temp = text.getTextureData();
        if (!temp.isPrepared()) {
            temp.prepare();
        }
        Pixmap currPixmap = temp.consumePixmap();
        Pixmap newPixmap = new Pixmap(text.getWidth(), text.getHeight(), Pixmap.Format.RGBA8888);
        newPixmap.setColor(new Color(0.0f, 0.0f, 0.0f, 0.0f));
        newPixmap.fill();
        int i = 0;
        int j = 0;
        while (j < text.getHeight()) {
            if (i > text.getWidth()) {
                i = -1;
                j++;
            } else {
                Color color = new Color(currPixmap.getPixel(i, j));
                if (((int) (color.r * 255.0f)) == 240 && ((int) (color.g * 255.0f)) == 208 && ((int) (color.b * 255.0f)) == 88) {
                    color.r = this.pokemon.sprite.color1.r;
                    color.g = this.pokemon.sprite.color1.g;
                    color.b = this.pokemon.sprite.color1.b;
                } else if (((int) (color.r * 255.0f)) == 184 && ((int) (color.g * 255.0f)) == 128 && ((int) (color.b * 255.0f)) == 0) {
                    color.r = this.pokemon.sprite.color2.r;
                    color.g = this.pokemon.sprite.color2.g;
                    color.b = this.pokemon.sprite.color2.b;
                }
                newPixmap.drawPixel(i, j, Color.rgba8888(color.r, color.g, color.b, color.a));
            }
            i++;
        }
        TextureCache.textMap.put(fileHandle, TextureCache.get(newPixmap));
        game.insertAction(this.nextAction);
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (isDone) {
            game.actionStack.remove(this);
            return;
        }
        game.uiBatch.draw(this.bgSprite, 0.0f, 0.0f);
        if (drawPostHatchTop) {
            this.pokemon.sprite.setRegionY(0);
            this.pokemon.sprite.setRegionHeight((int) this.pokemon.sprite.getHeight());
            drawSprite = true;
            drawPostHatchTop = false;
        }
        if (drawPostHatchBottom) {
            this.pokemon.sprite.setRegionY((((int) this.pokemon.sprite.getWidth()) - ((int) this.pokemon.sprite.getWidth())) + (((int) this.pokemon.sprite.getWidth()) / 2));
            this.pokemon.sprite.setRegionHeight(((int) this.pokemon.sprite.getWidth()) / 2);
            drawSprite = true;
            drawPostHatchBottom = false;
        }
        if (drawSprite) {
            game.uiBatch.draw(this.pokemon.sprite, (float) ((80 - (((int) this.pokemon.sprite.getWidth()) / 2)) + 4), 64.0f);
        }
    }

    /* compiled from: Battle.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/EggHatchAnim$Done.class */
    public static class Done extends Action {
        public int timer;

        public Done(int timer, Action nextAction) {
            super(new Object[0]);
            this.timer = 13;
            this.timer = timer;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            this.timer--;
            if (this.timer <= 0) {
                EggHatchAnim.isDone = true;
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            }
            EggHatchAnim.drawSprite = false;
        }
    }
}
